<template>
  <common-card title="今日销售额" :value="numberFormat(salesToday)">
    <div class="compare-wrap">
      <div class="compare">
        <div>日同比</div>
        <div class="emphasis">{{ salesGrowthLastDay }}%</div>
        <div :class="salesGrowthLastDay > 0 ? 'increment' : 'decrement'"></div>
      </div>
      <div class="compare">
        <div>月同比</div>
        <div class="emphasis">{{ salesGrowthLastMonth }}%</div>
        <div
          :class="salesGrowthLastMonth > 0 ? 'increment' : 'decrement'"
        ></div>
      </div>
    </div>
    <template #bottom>
      <span>昨日销售额</span>
      <span class="emphasis">{{ currencyFormat(salesLastDay) }}</span>
    </template>
  </common-card>
</template>

<script setup lang="ts">
import { ref, watch } from "vue";
import { useDataStore } from "@/stores/echartsData";
import useFormat from "@/hooks/useFormat";
// 实例化仓库
const dataStore = useDataStore();

const salesToday = ref<number>(0);
const salesLastDay = ref<number>(0);
const salesGrowthLastDay = ref<number>(0);
const salesGrowthLastMonth = ref<number>(0);

// 数据格式化
const { numberFormat, currencyFormat } = useFormat();

// 对数据进行监控
watch(dataStore, (newVal) => {
  salesToday.value = newVal.reportData.salesToday as number;
  salesLastDay.value = newVal.reportData.salesLastDay as number;
  salesGrowthLastDay.value = newVal.reportData.salesGrowthLastDay as number;
  salesGrowthLastMonth.value = newVal.reportData.salesGrowthLastMonth as number;
});
</script>

<script lang="ts">
export default {
  name: "TodaySales",
};
</script>

<style lang="scss" scoped>
.compare-wrap {
  height: 100%;
  display: flex;
  flex-direction: column;
  font-size: 12px;
  font-weight: 600;
  color: #666;
  .compare {
    flex: 1;
    display: flex;
    align-items: center;
  }
}
</style>
